package com.futvan.z.framework.util;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.CompactWriter;
import com.thoughtworks.xstream.io.xml.DomDriver;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class XmlUtil {
	
	public static void main(String[] args) throws Exception {
		String xml = "<hospitalList>\n" +
				"        <hospitalData>\n" +
				"            <hospitalOrgCode>Y</hospitalOrgCode>\n" +
				"            <orgCode>YHSOFT</orgCode>\n" +
				"            <orgName>银海软件</orgName>\n" +
				"            <hospitalAddr></hospitalAddr>\n" +
				"            <hospitalDesc></hospitalDesc>\n" +
				"            <hospitalGrade>HLL9</hospitalGrade>\n" +
				"            <hospitalLevel>HGD9</hospitalLevel>\n" +
				"            <hospitalType>HTPA1</hospitalType>\n" +
				"            <hospitalBookingRule></hospitalBookingRule>\n" +
				"            <hospitalWebUrl></hospitalWebUrl>\n" +
				"            <hospitalImage></hospitalImage>\n" +
				"            <areaCode></areaCode>\n" +
				"            <hospitalBranchList>\n" +
				"                <hospitalBranchData>\n" +
				"                    <hospitalBranchCode>2222</hospitalBranchCode>\n" +
				"                    <hospitalBranchName>大连市区</hospitalBranchName>\n" +
				"                    <hospitalBranchAddr></hospitalBranchAddr>\n" +
				"                </hospitalBranchData>\n" +
				"            </hospitalBranchList>\n" +
				"        </hospitalData>\n" +
				"        <hospitalData>\n" +
				"            <hospitalOrgCode>10440</hospitalOrgCode>\n" +
				"            <orgCode>111</orgCode>\n" +
				"            <orgName>大连测试医院</orgName>\n" +
				"            <hospitalAddr></hospitalAddr>\n" +
				"            <hospitalDesc></hospitalDesc>\n" +
				"            <hospitalGrade>HLL9</hospitalGrade>\n" +
				"            <hospitalLevel>HGD9</hospitalLevel>\n" +
				"            <hospitalType>HTPA1</hospitalType>\n" +
				"            <hospitalBookingRule></hospitalBookingRule>\n" +
				"            <hospitalWebUrl></hospitalWebUrl>\n" +
				"            <hospitalImage></hospitalImage>\n" +
				"            <areaCode></areaCode>\n" +
				"            <hospitalBranchList>\n" +
				"                <hospitalBranchData>\n" +
				"                    <hospitalBranchCode>11112</hospitalBranchCode>\n" +
				"                    <hospitalBranchName>大连测试医院（分院）</hospitalBranchName>\n" +
				"                    <hospitalBranchAddr></hospitalBranchAddr>\n" +
				"                </hospitalBranchData>\n" +
				"            </hospitalBranchList>\n" +
				"        </hospitalData>\n" +
				"        <hospitalData>\n" +
				"            <hospitalOrgCode>10422</hospitalOrgCode>\n" +
				"            <orgCode>0148</orgCode>\n" +
				"            <orgName>大连西岗白云莲花社区卫生服务中心</orgName>\n" +
				"            <hospitalAddr></hospitalAddr>\n" +
				"            <hospitalDesc></hospitalDesc>\n" +
				"            <hospitalGrade>HLL9</hospitalGrade>\n" +
				"            <hospitalLevel>HGD1</hospitalLevel>\n" +
				"            <hospitalType>HTPA1</hospitalType>\n" +
				"            <hospitalBookingRule></hospitalBookingRule>\n" +
				"            <hospitalWebUrl></hospitalWebUrl>\n" +
				"            <hospitalImage></hospitalImage>\n" +
				"            <areaCode>210203</areaCode>\n" +
				"            <hospitalBranchList/>\n" +
				"        </hospitalData>\n" +
				"        <hospitalData>\n" +
				"            <hospitalOrgCode>10423</hospitalOrgCode>\n" +
				"            <orgCode>0244</orgCode>\n" +
				"            <orgName>八一路社区卫生服务中心</orgName>\n" +
				"            <hospitalAddr></hospitalAddr>\n" +
				"            <hospitalDesc></hospitalDesc>\n" +
				"            <hospitalGrade>HLL9</hospitalGrade>\n" +
				"            <hospitalLevel>HGD1</hospitalLevel>\n" +
				"            <hospitalType>HTPA1</hospitalType>\n" +
				"            <hospitalBookingRule></hospitalBookingRule>\n" +
				"            <hospitalWebUrl></hospitalWebUrl>\n" +
				"            <hospitalImage></hospitalImage>\n" +
				"            <areaCode>210203</areaCode>\n" +
				"            <hospitalBranchList/>\n" +
				"        </hospitalData>\n" +
				"        <hospitalData>\n" +
				"            <hospitalOrgCode>10424</hospitalOrgCode>\n" +
				"            <orgCode>3530</orgCode>\n" +
				"            <orgName>付家庄服务站</orgName>\n" +
				"            <hospitalAddr></hospitalAddr>\n" +
				"            <hospitalDesc></hospitalDesc>\n" +
				"            <hospitalGrade>HLL9</hospitalGrade>\n" +
				"            <hospitalLevel>HGD1</hospitalLevel>\n" +
				"            <hospitalType>HTPA1</hospitalType>\n" +
				"            <hospitalBookingRule></hospitalBookingRule>\n" +
				"            <hospitalWebUrl></hospitalWebUrl>\n" +
				"            <hospitalImage></hospitalImage>\n" +
				"            <areaCode>210203</areaCode>\n" +
				"            <hospitalBranchList/>\n" +
				"        </hospitalData>\n" +
				"        <hospitalData>\n" +
				"            <hospitalOrgCode>10420</hospitalOrgCode>\n" +
				"            <orgCode>2222</orgCode>\n" +
				"            <orgName>大连市区</orgName>\n" +
				"            <hospitalAddr></hospitalAddr>\n" +
				"            <hospitalDesc></hospitalDesc>\n" +
				"            <hospitalGrade>HLL9</hospitalGrade>\n" +
				"            <hospitalLevel>HGD9</hospitalLevel>\n" +
				"            <hospitalType>HTPA1</hospitalType>\n" +
				"            <hospitalBookingRule></hospitalBookingRule>\n" +
				"            <hospitalWebUrl></hospitalWebUrl>\n" +
				"            <hospitalImage></hospitalImage>\n" +
				"            <areaCode></areaCode>\n" +
				"            <hospitalBranchList>\n" +
				"                <hospitalBranchData>\n" +
				"                    <hospitalBranchCode>111</hospitalBranchCode>\n" +
				"                    <hospitalBranchName>大连测试医院</hospitalBranchName>\n" +
				"                    <hospitalBranchAddr></hospitalBranchAddr>\n" +
				"                </hospitalBranchData>\n" +
				"                <hospitalBranchData>\n" +
				"                    <hospitalBranchCode>0148</hospitalBranchCode>\n" +
				"                    <hospitalBranchName>大连西岗白云莲花社区卫生服务中心</hospitalBranchName>\n" +
				"                    <hospitalBranchAddr></hospitalBranchAddr>\n" +
				"                </hospitalBranchData>\n" +
				"                <hospitalBranchData>\n" +
				"                    <hospitalBranchCode>0244</hospitalBranchCode>\n" +
				"                    <hospitalBranchName>八一路社区卫生服务中心</hospitalBranchName>\n" +
				"                    <hospitalBranchAddr></hospitalBranchAddr>\n" +
				"                </hospitalBranchData>\n" +
				"                <hospitalBranchData>\n" +
				"                    <hospitalBranchCode>3530</hospitalBranchCode>\n" +
				"                    <hospitalBranchName>付家庄服务站</hospitalBranchName>\n" +
				"                    <hospitalBranchAddr></hospitalBranchAddr>\n" +
				"                </hospitalBranchData>\n" +
				"                <hospitalBranchData>\n" +
				"                    <hospitalBranchCode>0119</hospitalBranchCode>\n" +
				"                    <hospitalBranchName>大连西岗日新社区卫生服务中心</hospitalBranchName>\n" +
				"                    <hospitalBranchAddr></hospitalBranchAddr>\n" +
				"                </hospitalBranchData>\n" +
				"                <hospitalBranchData>\n" +
				"                    <hospitalBranchCode>0371</hospitalBranchCode>\n" +
				"                    <hospitalBranchName>大连西岗日新社区卫生服务中心广和社区卫生服务站</hospitalBranchName>\n" +
				"                    <hospitalBranchAddr></hospitalBranchAddr>\n" +
				"                </hospitalBranchData>\n" +
				"                <hospitalBranchData>\n" +
				"                    <hospitalBranchCode>0138</hospitalBranchCode>\n" +
				"                    <hospitalBranchName>大连西岗北京长江路社区卫生服务中心</hospitalBranchName>\n" +
				"                    <hospitalBranchAddr></hospitalBranchAddr>\n" +
				"                </hospitalBranchData>\n" +
				"                <hospitalBranchData>\n" +
				"                    <hospitalBranchCode>XYYH</hospitalBranchCode>\n" +
				"                    <hospitalBranchName>兴业银行</hospitalBranchName>\n" +
				"                    <hospitalBranchAddr></hospitalBranchAddr>\n" +
				"                </hospitalBranchData>\n" +
				"                <hospitalBranchData>\n" +
				"                    <hospitalBranchCode>0637</hospitalBranchCode>\n" +
				"                    <hospitalBranchName>大连西岗日新社区卫生服务中心平等社区卫生服务站</hospitalBranchName>\n" +
				"                    <hospitalBranchAddr></hospitalBranchAddr>\n" +
				"                </hospitalBranchData>\n" +
				"                <hospitalBranchData>\n" +
				"                    <hospitalBranchCode>3531</hospitalBranchCode>\n" +
				"                    <hospitalBranchName>大连西岗站北民乐社区卫生服务中心</hospitalBranchName>\n" +
				"                    <hospitalBranchAddr>大连市西岗区胜利街40号</hospitalBranchAddr>\n" +
				"                </hospitalBranchData>\n" +
				"                <hospitalBranchData>\n" +
				"                    <hospitalBranchCode>0999</hospitalBranchCode>\n" +
				"                    <hospitalBranchName>大连西岗日新社区卫生服务中心更新社区卫生服务站</hospitalBranchName>\n" +
				"                    <hospitalBranchAddr></hospitalBranchAddr>\n" +
				"                </hospitalBranchData>\n" +
				"                <hospitalBranchData>\n" +
				"                    <hospitalBranchCode>6456789</hospitalBranchCode>\n" +
				"                    <hospitalBranchName>新测试医院</hospitalBranchName>\n" +
				"                    <hospitalBranchAddr></hospitalBranchAddr>\n" +
				"                </hospitalBranchData>\n" +
				"            </hospitalBranchList>\n" +
				"        </hospitalData>\n" +
				"        <hospitalData>\n" +
				"            <hospitalOrgCode>10430</hospitalOrgCode>\n" +
				"            <orgCode>0119</orgCode>\n" +
				"            <orgName>大连西岗日新社区卫生服务中心</orgName>\n" +
				"            <hospitalAddr></hospitalAddr>\n" +
				"            <hospitalDesc></hospitalDesc>\n" +
				"            <hospitalGrade>HLL9</hospitalGrade>\n" +
				"            <hospitalLevel>HGD1</hospitalLevel>\n" +
				"            <hospitalType>HTPA3</hospitalType>\n" +
				"            <hospitalBookingRule></hospitalBookingRule>\n" +
				"            <hospitalWebUrl></hospitalWebUrl>\n" +
				"            <hospitalImage></hospitalImage>\n" +
				"            <areaCode>210203</areaCode>\n" +
				"            <hospitalBranchList/>\n" +
				"        </hospitalData>\n" +
				"        <hospitalData>\n" +
				"            <hospitalOrgCode>10434</hospitalOrgCode>\n" +
				"            <orgCode>0371</orgCode>\n" +
				"            <orgName>大连西岗日新社区卫生服务中心广和社区卫生服务站</orgName>\n" +
				"            <hospitalAddr></hospitalAddr>\n" +
				"            <hospitalDesc></hospitalDesc>\n" +
				"            <hospitalGrade>HLL9</hospitalGrade>\n" +
				"            <hospitalLevel>HGD1</hospitalLevel>\n" +
				"            <hospitalType>HTPA3</hospitalType>\n" +
				"            <hospitalBookingRule></hospitalBookingRule>\n" +
				"            <hospitalWebUrl></hospitalWebUrl>\n" +
				"            <hospitalImage></hospitalImage>\n" +
				"            <areaCode>210203</areaCode>\n" +
				"            <hospitalBranchList/>\n" +
				"        </hospitalData>\n" +
				"        <hospitalData>\n" +
				"            <hospitalOrgCode>10504</hospitalOrgCode>\n" +
				"            <orgCode>0138</orgCode>\n" +
				"            <orgName>大连西岗北京长江路社区卫生服务中心</orgName>\n" +
				"            <hospitalAddr></hospitalAddr>\n" +
				"            <hospitalDesc></hospitalDesc>\n" +
				"            <hospitalGrade>HLL9</hospitalGrade>\n" +
				"            <hospitalLevel>HGD1</hospitalLevel>\n" +
				"            <hospitalType>HTPA1</hospitalType>\n" +
				"            <hospitalBookingRule></hospitalBookingRule>\n" +
				"            <hospitalWebUrl></hospitalWebUrl>\n" +
				"            <hospitalImage></hospitalImage>\n" +
				"            <areaCode>210203</areaCode>\n" +
				"            <hospitalBranchList>\n" +
				"                <hospitalBranchData>\n" +
				"                    <hospitalBranchCode>01381</hospitalBranchCode>\n" +
				"                    <hospitalBranchName>大连西岗北京长江路社区卫生服务中心英山分站</hospitalBranchName>\n" +
				"                    <hospitalBranchAddr></hospitalBranchAddr>\n" +
				"                </hospitalBranchData>\n" +
				"            </hospitalBranchList>\n" +
				"        </hospitalData>\n" +
				"        <hospitalData>\n" +
				"            <hospitalOrgCode>10460</hospitalOrgCode>\n" +
				"            <orgCode>XYYH</orgCode>\n" +
				"            <orgName>兴业银行</orgName>\n" +
				"            <hospitalAddr></hospitalAddr>\n" +
				"            <hospitalDesc></hospitalDesc>\n" +
				"            <hospitalGrade></hospitalGrade>\n" +
				"            <hospitalLevel>HGD1</hospitalLevel>\n" +
				"            <hospitalType>HTPA1</hospitalType>\n" +
				"            <hospitalBookingRule></hospitalBookingRule>\n" +
				"            <hospitalWebUrl></hospitalWebUrl>\n" +
				"            <hospitalImage></hospitalImage>\n" +
				"            <areaCode></areaCode>\n" +
				"            <hospitalBranchList/>\n" +
				"        </hospitalData>\n" +
				"        <hospitalData>\n" +
				"            <hospitalOrgCode>10433</hospitalOrgCode>\n" +
				"            <orgCode>0637</orgCode>\n" +
				"            <orgName>大连西岗日新社区卫生服务中心平等社区卫生服务站</orgName>\n" +
				"            <hospitalAddr></hospitalAddr>\n" +
				"            <hospitalDesc></hospitalDesc>\n" +
				"            <hospitalGrade>HLL9</hospitalGrade>\n" +
				"            <hospitalLevel>HGD1</hospitalLevel>\n" +
				"            <hospitalType>HTPA3</hospitalType>\n" +
				"            <hospitalBookingRule></hospitalBookingRule>\n" +
				"            <hospitalWebUrl></hospitalWebUrl>\n" +
				"            <hospitalImage></hospitalImage>\n" +
				"            <areaCode>210203</areaCode>\n" +
				"            <hospitalBranchList/>\n" +
				"        </hospitalData>\n" +
				"        <hospitalData>\n" +
				"            <hospitalOrgCode>10442</hospitalOrgCode>\n" +
				"            <orgCode>3531</orgCode>\n" +
				"            <orgName>大连西岗站北民乐社区卫生服务中心</orgName>\n" +
				"            <hospitalAddr>大连市西岗区胜利街40号</hospitalAddr>\n" +
				"            <hospitalDesc></hospitalDesc>\n" +
				"            <hospitalGrade>HLL9</hospitalGrade>\n" +
				"            <hospitalLevel>HGD9</hospitalLevel>\n" +
				"            <hospitalType>HTPA1</hospitalType>\n" +
				"            <hospitalBookingRule></hospitalBookingRule>\n" +
				"            <hospitalWebUrl></hospitalWebUrl>\n" +
				"            <hospitalImage></hospitalImage>\n" +
				"            <areaCode>210203</areaCode>\n" +
				"            <hospitalBranchList>\n" +
				"                <hospitalBranchData>\n" +
				"                    <hospitalBranchCode>35311</hospitalBranchCode>\n" +
				"                    <hospitalBranchName>西岗站北民乐社区卫生服务中心团结社区卫生服务站</hospitalBranchName>\n" +
				"                    <hospitalBranchAddr></hospitalBranchAddr>\n" +
				"                </hospitalBranchData>\n" +
				"                <hospitalBranchData>\n" +
				"                    <hospitalBranchCode>35312</hospitalBranchCode>\n" +
				"                    <hospitalBranchName>西岗站北民乐社区卫生服务中心万全社区卫生服务站</hospitalBranchName>\n" +
				"                    <hospitalBranchAddr></hospitalBranchAddr>\n" +
				"                </hospitalBranchData>\n" +
				"            </hospitalBranchList>\n" +
				"        </hospitalData>\n" +
				"        <hospitalData>\n" +
				"            <hospitalOrgCode>10447</hospitalOrgCode>\n" +
				"            <orgCode>0999</orgCode>\n" +
				"            <orgName>大连西岗日新社区卫生服务中心更新社区卫生服务站</orgName>\n" +
				"            <hospitalAddr></hospitalAddr>\n" +
				"            <hospitalDesc></hospitalDesc>\n" +
				"            <hospitalGrade>HLL9</hospitalGrade>\n" +
				"            <hospitalLevel>HGD1</hospitalLevel>\n" +
				"            <hospitalType>HTPA3</hospitalType>\n" +
				"            <hospitalBookingRule></hospitalBookingRule>\n" +
				"            <hospitalWebUrl></hospitalWebUrl>\n" +
				"            <hospitalImage></hospitalImage>\n" +
				"            <areaCode></areaCode>\n" +
				"            <hospitalBranchList/>\n" +
				"        </hospitalData>\n" +
				"        <hospitalData>\n" +
				"            <hospitalOrgCode>10444</hospitalOrgCode>\n" +
				"            <orgCode>35311</orgCode>\n" +
				"            <orgName>西岗站北民乐社区卫生服务中心团结社区卫生服务站</orgName>\n" +
				"            <hospitalAddr></hospitalAddr>\n" +
				"            <hospitalDesc></hospitalDesc>\n" +
				"            <hospitalGrade>HLL9</hospitalGrade>\n" +
				"            <hospitalLevel>HGD9</hospitalLevel>\n" +
				"            <hospitalType>HTPA1</hospitalType>\n" +
				"            <hospitalBookingRule></hospitalBookingRule>\n" +
				"            <hospitalWebUrl></hospitalWebUrl>\n" +
				"            <hospitalImage></hospitalImage>\n" +
				"            <areaCode>210203</areaCode>\n" +
				"            <hospitalBranchList/>\n" +
				"        </hospitalData>\n" +
				"        <hospitalData>\n" +
				"            <hospitalOrgCode>10445</hospitalOrgCode>\n" +
				"            <orgCode>11112</orgCode>\n" +
				"            <orgName>大连测试医院（分院）</orgName>\n" +
				"            <hospitalAddr></hospitalAddr>\n" +
				"            <hospitalDesc></hospitalDesc>\n" +
				"            <hospitalGrade>HLL9</hospitalGrade>\n" +
				"            <hospitalLevel>HGD9</hospitalLevel>\n" +
				"            <hospitalType>HTPA1</hospitalType>\n" +
				"            <hospitalBookingRule></hospitalBookingRule>\n" +
				"            <hospitalWebUrl></hospitalWebUrl>\n" +
				"            <hospitalImage></hospitalImage>\n" +
				"            <areaCode></areaCode>\n" +
				"            <hospitalBranchList/>\n" +
				"        </hospitalData>\n" +
				"        <hospitalData>\n" +
				"            <hospitalOrgCode>10465</hospitalOrgCode>\n" +
				"            <orgCode>35312</orgCode>\n" +
				"            <orgName>西岗站北民乐社区卫生服务中心万全社区卫生服务站</orgName>\n" +
				"            <hospitalAddr></hospitalAddr>\n" +
				"            <hospitalDesc></hospitalDesc>\n" +
				"            <hospitalGrade>HLL9</hospitalGrade>\n" +
				"            <hospitalLevel>HGD9</hospitalLevel>\n" +
				"            <hospitalType>HTPA1</hospitalType>\n" +
				"            <hospitalBookingRule></hospitalBookingRule>\n" +
				"            <hospitalWebUrl></hospitalWebUrl>\n" +
				"            <hospitalImage></hospitalImage>\n" +
				"            <areaCode>210203</areaCode>\n" +
				"            <hospitalBranchList/>\n" +
				"        </hospitalData>\n" +
				"        <hospitalData>\n" +
				"            <hospitalOrgCode>10505</hospitalOrgCode>\n" +
				"            <orgCode>01381</orgCode>\n" +
				"            <orgName>大连西岗北京长江路社区卫生服务中心英山分站</orgName>\n" +
				"            <hospitalAddr></hospitalAddr>\n" +
				"            <hospitalDesc></hospitalDesc>\n" +
				"            <hospitalGrade>HLL9</hospitalGrade>\n" +
				"            <hospitalLevel>HGD1</hospitalLevel>\n" +
				"            <hospitalType>HTPA1</hospitalType>\n" +
				"            <hospitalBookingRule></hospitalBookingRule>\n" +
				"            <hospitalWebUrl></hospitalWebUrl>\n" +
				"            <hospitalImage></hospitalImage>\n" +
				"            <areaCode>210203</areaCode>\n" +
				"            <hospitalBranchList/>\n" +
				"        </hospitalData>\n" +
				"        <hospitalData>\n" +
				"            <hospitalOrgCode>110419</hospitalOrgCode>\n" +
				"            <orgCode>6456789</orgCode>\n" +
				"            <orgName>新测试医院</orgName>\n" +
				"            <hospitalAddr></hospitalAddr>\n" +
				"            <hospitalDesc></hospitalDesc>\n" +
				"            <hospitalGrade>HLL2</hospitalGrade>\n" +
				"            <hospitalLevel>HGD1</hospitalLevel>\n" +
				"            <hospitalType>HTPA1</hospitalType>\n" +
				"            <hospitalBookingRule></hospitalBookingRule>\n" +
				"            <hospitalWebUrl></hospitalWebUrl>\n" +
				"            <hospitalImage></hospitalImage>\n" +
				"            <areaCode></areaCode>\n" +
				"            <hospitalBranchList/>\n" +
				"        </hospitalData>\n" +
				"    </hospitalList>\n" +
				"\n";


		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		DocumentBuilder db = dbf.newDocumentBuilder();
		StringReader sr = new StringReader(xml);
		InputSource is = new InputSource(sr);
		Document document = db.parse(is);
		NodeList list = document.getDocumentElement().getChildNodes();
		for (int i = 0; i < list.getLength(); i++) {
			Node item = list.item(i);
			System.out.println(item.getNodeName());
		}

	}

	/**
	 * 对象转XML报文
	 * 
	 * @param obj
	 * @return
	 */
	public static String ObjectToXml(Object obj,String class_name,java.lang.Class class_info) {
		String returnvalue = null;
		XStream xstream = new XStream(new DomDriver());
		xstream.alias(class_name, class_info);
		returnvalue = xstream.toXML(obj);
		returnvalue = returnvalue.replace("&lt;", "<");
		returnvalue = returnvalue.replace("&gt;", ">");
		return returnvalue;
	}

	/**
	 * 对象转XML报文
	 * 
	 * @param obj
	 * @param alias
	 * @return
	 */
	public static String ObjectToXml(Object obj,HashMap<String,java.lang.Class> alias) {
		String returnvalue = null;
		XStream xstream = new XStream(new DomDriver());
		if (alias != null) {
			for (String key : alias.keySet()) {
				xstream.alias(key, alias.get(key));
			}
		}
		returnvalue = xstream.toXML(obj);
		returnvalue = returnvalue.replace("&lt;", "<");
		returnvalue = returnvalue.replace("&gt;", ">");
		returnvalue = returnvalue.replace("&quot;", "\"");
		return returnvalue;
	}

	/**
	 * 对象转XML报文
	 * 
	 * @param obj
	 * @param alias
	 * @return
	 */
	public static String ObjectToXml(Object obj,HashMap<String, java.lang.Class> alias,HashMap<String, java.lang.Class> useAttribute) {
		String returnvalue = "";
		XStream xstream = new XStream(new DomDriver());
		if (alias != null) {
			for (String key : alias.keySet()) {
				xstream.alias(key, alias.get(key));
			}
		}

		if (useAttribute != null) {
			for (String key : useAttribute.keySet()) {
				xstream.useAttributeFor(useAttribute.get(key), key);
			}
		}
		returnvalue = xstream.toXML(obj);
		returnvalue = returnvalue.replace("&lt;", "<");
		returnvalue = returnvalue.replace("&gt;", ">");
		return returnvalue;
	}

	/**
	 * 对象转XML报文（无格式输出）
	 * 
	 * @param obj
	 * @param alias
	 * @return
	 */
	public static String ObjectToXmlNoFormat(Object obj,HashMap<String, java.lang.Class> alias) {
		String returnvalue = "";
		XStream xstream = new XStream(new DomDriver());
		if (alias != null) {
			for (String key : alias.keySet()) {
				xstream.alias(key, alias.get(key));
			}
		}
		Writer writer = new StringWriter();
		xstream.marshal(obj, new CompactWriter(writer));
		returnvalue = writer.toString();
		return returnvalue;
	}

	/**
	 * 对象转XML报文（无格式输出）
	 * 
	 * @param obj
	 * @param alias
	 * @return
	 */
	public static String ObjectToXmlNoFormat(Object obj,HashMap<String, java.lang.Class> alias,HashMap<String, java.lang.Class> useAttribute) {
		String returnvalue = "";
		XStream xstream = new XStream(new DomDriver());
		if (alias != null) {
			for (String key : alias.keySet()) {
				xstream.alias(key, alias.get(key));
			}
		}
		if (useAttribute != null) {
			for (String key : useAttribute.keySet()) {
				xstream.useAttributeFor(useAttribute.get(key), key);
			}
		}

		Writer writer = new StringWriter();
		xstream.marshal(obj, new CompactWriter(writer));
		returnvalue = writer.toString();
		return returnvalue;
	}

	/**
	 * XMl转对象
	 * 
	 * @param xml
	 * @return
	 */
	public static Object XmlToObject(String xml,HashMap<String, java.lang.Class> alias) {
		Object obj = null;
		XStream xstream = new XStream(new DomDriver());
		// 忽略未知字段
		xstream.ignoreUnknownElements();
		// 添加字参数替换
		if (alias != null) {
			for (String key : alias.keySet()) {
				xstream.alias(key, alias.get(key));
			}
		}
		obj = xstream.fromXML(xml);
		return obj;
	}

	/**
	 * XMl转对象
	 * 
	 * @param xml
	 * @param class_name
	 * @param class_info
	 * @return
	 */
	public static Object XmlToObject(String xml, String class_name,java.lang.Class class_info) {
		Object obj = null;
		XStream xstream = new XStream(new DomDriver());
		// 忽略未知字段
		xstream.ignoreUnknownElements();
		xstream.alias(class_name, class_info);
		obj = xstream.fromXML(xml);
		return obj;
	}

	/**
	 * XML字符串转为Map
	 * 
	 * @param xml
	 * @return
	 * @throws Exception
	 */
	public static Map<String, Object> parseXml(String xml) throws Exception {
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		DocumentBuilder db = dbf.newDocumentBuilder();

		StringReader sr = new StringReader(xml);
		InputSource is = new InputSource(sr);

		Document document = db.parse(is);

		Map<String, Object> result = new HashMap<String, Object>();

		NodeList list = document.getDocumentElement().getChildNodes();
		for (int i = 0; i < list.getLength(); i++) {
			Node item = list.item(i);
			if (item.getNodeType() == Node.ELEMENT_NODE) {
				result.put(item.getNodeName(), item.getTextContent().trim());
			}
		}
		return result;
	}

	/**
	 * Map转为XML字符串
	 * 
	 * @param map
	 * @return
	 */
	public static String toXml(Map<String, Object> map) {
		StringBuilder sb = new StringBuilder();
		sb.append("<xml>");
		for (String key : map.keySet()) {
			sb.append("<" + key + ">" + map.get(key) + "</" + key + ">");
		}
		sb.append("</xml>");
		return sb.toString();
	}
}